#!/usr/bin/env bash

. ./test.common

test_start "maxunreach option"

limit=5000
servers=2
client_server_options="minpoll 6 maxpoll 6 minsamples 64"
base_delay=$(cat <<-EOF | tr -d '\n'
  (+ 1e-4
     (* -1
        (equal 0.1 from 3)
        (equal 0.1 to 1)
        (equal 0.1 (min time 2000) 2000))
     (* 0.5
        (+ (equal 0.1 from 2)
           (equal 0.1 to 2))))
EOF
)

run_test || test_fail
check_chronyd_exit || test_fail
check_source_selection || test_fail
check_packet_interval || test_fail
check_sync || test_fail

check_log_messages "Selected source 192.168.123.1" 1 1 || test_fail
check_log_messages "Selected source 192.168.123.2" 0 0 || test_fail

client_server_options="minpoll 6 maxpoll 6 minsamples 64 maxunreach 10"

run_test || test_fail
check_chronyd_exit || test_fail
check_source_selection || test_fail
check_packet_interval || test_fail
check_sync || test_fail

check_log_messages "Selected source 192.168.123.1" 1 1 || test_fail
check_log_messages "Selected source 192.168.123.2" 1 1 || test_fail
check_log_messages "00:52:..Z Selected source 192.168.123.2" 1 1 || test_fail

test_pass
